import { createRouter, createWebHistory } from 'vue-router'

// 创建Vue Router实例
const router = createRouter({
  // 使用浏览器历史记录进行路由管理
  history: createWebHistory(import.meta.env.BASE_URL),
  // 定义路由规则
  routes: [
    // 登录页: 一级路由
    {
      path: '/login',
      component: () => import('@/views/login/LoginPage.vue')
    },
    // layout容器: 一级路由
    {
      path: '/',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      // 默认重定向到文章管理页面
      redirect: '/article/manage',
      // 二级路由
      children: [
        {
          path: '/article/manage',
          component: () => import('@/views/article/ArticleManage.vue')
        },
        {
          path: '/article/channel',
          component: () => import('@/views/article/ArticleChannel.vue')
        },
        {
          path: '/user/profile',
          component: () => import('@/views/user/UserProfile.vue')
        },
        {
          path: '/user/avatar',
          component: () => import('@/views/user/UserAvatar.vue')
        },
        {
          path: '/user/password',
          component: () => import('@/views/user/UserPassword.vue')
        }
      ]
    }
  ]
})

// 导出router实例供全局使用
export default router
